from typing import Annotated

from langgraph.constants import START,END
from langgraph.graph import StateGraph
from typing_extensions import TypedDict
import operator

class State(TypedDict):
    aggregated:Annotated[list,operator.add]

def a(state: State) -> State:
    print("a===")
    return {"aggregated":["a"]}

def b(state: State) -> State:
    print("b===")
    return {"aggregated":["b"]}

def c(state: State) -> State:
    print("c===")
    return {"aggregated":["c"]}

def d(state: State) -> State:
    print("d===")
    return {"aggregated":["d"]}


builder = StateGraph(State)
builder.add_node(a)
builder.add_node(b)
builder.add_node(c)
builder.add_node(d)

builder.add_edge(START,"a")
builder.add_edge("a","b")
builder.add_edge("a","c")
builder.add_edge("b","d")
builder.add_edge("c","d")
builder.add_edge("d",END)

graph = builder.compile()
ss = graph.invoke({"aggregated":[]},{"configrable":{"thread_id":"foo"}})
print(ss)


